package com.shan.design.combination.transparent;

import com.shan.design.combination.safe.*;

/**
 * description
 * 组合模式测试类
 *
 * @author shanzheng <br/>
 * @date 17:19 2018/11/29.<br/>
 * Modified By <br/>
 */
public class CombinationTest {
    /*
    * 何为组合模式：组合多个对象形成树形结构以表示具有“整体—部分”关系的层次结构
    * 解决的问题：由于容器对象和叶子对象在功能上有区别，在使用这些对象必须要有区别，但是区别对待会造成程序
    * 比较复杂，组合模式就是为了解决这样的问题，可以让容器对象和叶子对象的使用具有一致性
    * 组成部分：Component抽象构件、Leaf叶子构件、Composite容器构件
    * 参考地址：https://gof.quanke.name/
    * */

    public static void main(String[] args) {
        //针对抽象构件编程
        AbstractFile file1, file2, file3, file4, file5, folder1, folder2, folder3, folder4;

        folder1 = new Folder("Sunny的资料");
        folder2 = new Folder("图像文件");
        folder3 = new Folder("文本文件");
        folder4 = new Folder("视频文件");

        file1 = new ImageFile("小龙女.jpg");
        file2 = new ImageFile("张无忌.gif");
        file3 = new TextFile("九阴真经.txt");
        file4 = new TextFile("葵花宝典.doc");
        file5 = new VideoFile("笑傲江湖.rmvb");

        folder2.add(file1);
        folder2.add(file2);
        folder3.add(file3);
        folder3.add(file4);
        folder4.add(file5);
        folder1.add(folder2);
        folder1.add(folder3);
        folder1.add(folder4);
        folder1.killVirus();

        // 安全组合模式
        FolderSafe folderSafe1,folderSafe2,folderSafe3,folderSafe4;
        AbstractFileSafe abstractFileSafe1,abstractFileSafe2,abstractFileSafe3,abstractFileSafe4,abstractFileSafe5;
        folderSafe1 = new FolderSafe("Sunny的资料");
        folderSafe2 = new FolderSafe("图像文件");
        folderSafe3 = new FolderSafe("文本文件");
        folderSafe4 = new FolderSafe("视频文件");
        abstractFileSafe1 = new ImageFileSafe("小龙女.jpg");
        abstractFileSafe2 = new ImageFileSafe("张无忌.gif");
        abstractFileSafe3 = new TextFileSafe("九阴真经.txt");
        abstractFileSafe4 = new TextFileSafe("葵花宝典.doc");
        abstractFileSafe5 = new VideoFileSafe("笑傲江湖.rmvb");
        folderSafe2.add(abstractFileSafe1);
        folderSafe2.add(abstractFileSafe2);
        folderSafe3.add(abstractFileSafe3);
        folderSafe3.add(abstractFileSafe4);
        folderSafe4.add(abstractFileSafe5);
        folderSafe1.add(folderSafe2);
        folderSafe1.add(folderSafe3);
        folderSafe1.add(folderSafe4);
        folderSafe1.killVirus();
    }
}
